#include "utf8_string.h"

#include <stdio.h>
#include <string.h>

void simple_test(const utf8_string& utf8string) {
    utf8string.output(stdout);
    printf("length: %d\n", utf8string.length());
    for (int i = 0; i < utf8string.length(); ++i) {
        utf8_char curr_char = utf8string.at(i);
        printf("at %d: ", i);
        curr_char.print_to(stdout);
        printf("\n");
    }
}

void readline_and_test(utf8_string* utf8string, char const * output) {
    printf("%s", output);
    char test_string[1024];
    fgets(test_string, 1024, stdin);
    // remove the last \n
    int len = strlen(test_string);
    test_string[len-1] = '\0';
    utf8string->from_bytes(test_string);
    simple_test(*utf8string);
}

int main() {
    utf8_string utf8string, utf8string2, utf8string3;
    utf8_string to;
    to.from_bytes("****");
    readline_and_test(&utf8string, "put one string:\n");
    readline_and_test(&utf8string2, "put another string:\n");

    utf8string3 = utf8string.concat(utf8string2);
    simple_test(utf8string3);

    utf8string3 = utf8string2.concat(utf8string);
    simple_test(utf8string3);

    printf("utf8string3.find(utf8string): %d\n",
           utf8string3.find(utf8string));

    printf("utf8string.find(utf8string2): %d\n",
           utf8string.find(utf8string2));

    printf("utf8string.replace(utf8string2): %d\n",
           utf8string.replace(utf8string2, to));

    utf8string.output(stdout);

    return 0;
}
